package cn.tx.four;

import cn.tx.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * 交换机直连模式
 * @author Mxb
 * @version 1.0
 * @date 2020/10/4 17:28
 */
public class Producer {
    @Test
    public void sendMessage() throws Exception{
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        String exchangeName = "logs_direct";
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);
        //声明一个路由key
        String routingKey="info";
        channel.basicPublish(exchangeName,routingKey,null,
                ("我是一个直连类型的交换机消息-routingKey:"+routingKey).getBytes());
        System.out.println("消息发送成功");
        RabbitMQUtils.closeChannelAndConnection(channel,connection);
    }
}
